<template>
  <div class="login-container">
    <div class="login-box">
      <div class="logo">
        <img src="https://img.yzcdn.cn/vant/logo.png" alt="logo" />
      </div>
      <h2>微信注册</h2>
      <form @submit.prevent="onRegister">
        <div class="form-group">
          <label for="username">用户名</label>
          <input type="text" id="username" v-model="form.username" required autocomplete="username">
        </div>
        <div class="form-group">
          <label for="password">密码</label>
          <input type="password" id="password" v-model="form.password" required autocomplete="new-password">
        </div>
        <div class="form-group">
          <label for="nickname">昵称</label>
          <input type="text" id="nickname" v-model="form.nickname" required autocomplete="off">
        </div>
        <button type="submit">注册</button>
      </form>
      <p class="register-tip">
        已有账号？
        <router-link to="/login">去登录</router-link>
      </p>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'RegisterPage',
  data() {
    return {
      form: {
        username: '',
        password: '',
        nickname: ''
      },
      loading: false
    }
  },
  methods: {
    async onRegister() {
      if (this.loading) return
      this.loading = true
      try {
        await axios.post('/api/user/register', this.form)
        alert('注册成功，请登录')
        this.$router.push('/login')
      } catch (e) {
        alert(e.response?.data?.message || '注册失败')
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e5e6eb;
}
.login-box {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.10);
  padding: 40px 36px 30px 36px;
  min-width: 350px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.logo img {
  width: 56px;
  height: 56px;
  margin-bottom: 12px;
  border-radius: 12px;
}
h2 {
  text-align: center;
  margin-bottom: 28px;
  color: #222;
  font-weight: 700;
  letter-spacing: 2px;
}
form {
  width: 100%;
}
.form-group {
  margin-bottom: 20px;
  width: 100%;
  display: flex;
  align-items: center;
}
label {
  width: 70px;
  margin-right: 10px;
  color: #666;
  font-size: 15px;
  text-align: right;
  flex-shrink: 0;
}
input[type="text"], input[type="password"] {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #dcdfe6;
  border-radius: 6px;
  outline: none;
  font-size: 15px;
  transition: border-color 0.2s;
  background: #f7f8fa;
}
input[type="text"]:focus, input[type="password"]:focus {
  border-color: #07c160;
  background: #fff;
}
button[type="submit"] {
  width: 100%;
  padding: 10px 0;
  background: #07c160;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.2s;
  box-shadow: 0 2px 8px rgba(7,193,96,0.08);
}
button[type="submit"]:hover:not(:disabled) {
  background: #13ce66;
}
button[type="submit"]:disabled {
  background: #b2f2d7;
  cursor: not-allowed;
}
.register-tip {
  margin-top: 22px;
  text-align: right;
  font-size: 15px;
  width: 100%;
}
.register-tip a {
  color: #07c160;
  text-decoration: none;
  margin-left: 4px;
}
.register-tip a:hover {
  text-decoration: underline;
}
</style> 